****APPENDIX TABLE C9****

cd "$main_dir/output/tables/appendix_c"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_pwt_barro_var_exp.dta", nogen keepusing(pwtbar_total_growth_rate_obs pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc)

fegen ccode_survey_year = group(ccode survey_year)
fegen subregion_yob = group(subregion yob) if yob!=-99
fegen ccode_age = group(ccode age) if age!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop pwtbar_sample pwtbar_gallup_sample
gen pwtbar_sample = 1 if born_country!=0 & pwtbar_total_growth_rate_obs>=0.9*(age-1) & pwtbar_total_growth_rate_obs!=.
gen pwtbar_gallup_sample = 1 if born_country==1 & pwtbar_total_growth_rate_obs>=0.9*(age-1) & pwtbar_total_growth_rate_obs!=. & survey=="Gallup"
replace pwtbar_gallup_sample = 1 if pwtbar_total_growth_rate_obs>=0.9*(age-1) & pwtbar_total_growth_rate_obs!=. & survey=="Gallup" & (born_country!=0) & survey_year==2006

//--------------------------------------------------------
//Create Table C9
//--------------------------------------------------------

//Column 1
qui reghdfe trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc if pwtbar_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zpwtbar_wgrowth_rate_1 zpwtbar_yob_ln_gdppc if pwtbar_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_c9.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
													    Age FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, No, ///
														Country FE x Age FE, No, ///
													    Survey, Harmonized) keep(zpwtbar_wgrowth_rate_1) 													

//Column 2
qui reghdfe trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc if pwtbar_sample==1, absorb(ccode_survey_year svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zpwtbar_wgrowth_rate_1 zpwtbar_yob_ln_gdppc if pwtbar_sample==1, absorb(ccode_survey_year svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_c9.doc, append dec(3) nocons addtext(Country FE, No, ///
													    Age FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, No, ///
													    Survey, Harmonized) keep(zpwtbar_wgrowth_rate_1) 

//Column 3
qui reghdfe trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc if pwtbar_sample==1, absorb(ccode_survey_year ccode_age svy_survey_year subregion_yob $basic) cluster(ccode)
cap drop z*
local varlist trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zpwtbar_wgrowth_rate_1 zpwtbar_yob_ln_gdppc if pwtbar_sample==1, absorb(ccode_survey_year ccode_age svy_survey_year subregion_yob $basic) cluster(ccode)
outreg2 using table_c9.doc, append dec(3) nocons addtext(Country FE, No, ///
													    Age FE, No, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, Yes, ///
													    Survey, Harmonized) keep(zpwtbar_wgrowth_rate_1) 

//Column 4
qui reghdfe trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc if pwtbar_gallup_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zpwtbar_wgrowth_rate_1 zpwtbar_yob_ln_gdppc if pwtbar_gallup_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_c9.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													    Age FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, No, ///
														Country FE x Age FE, No, ///
													    Survey, Gallup) keep(zpwtbar_wgrowth_rate_1) 	

//Column 5
qui reghdfe trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc if pwtbar_gallup_sample==1, absorb(ccode_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zpwtbar_wgrowth_rate_1 zpwtbar_yob_ln_gdppc if pwtbar_gallup_sample==1, absorb(ccode_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_c9.doc, append dec(3) nocons addtext(Country FE, No, ///
													    Age FE, Yes, ///
														Survey Year FE x Survey FE, No, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, No, ///
													    Survey, Gallup) keep(zpwtbar_wgrowth_rate_1) 															

//Column 6
qui reghdfe trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc if pwtbar_gallup_sample==1, absorb(ccode_survey_year ccode_age subregion_yob $basic) cluster(ccode)
cap drop z*
local varlist trust_govt pwtbar_wgrowth_rate_1 pwtbar_yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zpwtbar_wgrowth_rate_1 zpwtbar_yob_ln_gdppc if pwtbar_gallup_sample==1, absorb(ccode_survey_year ccode_age subregion_yob $basic) cluster(ccode)
outreg2 using table_c9.doc, append dec(3) nocons addtext(Country FE, No, ///
													    Age FE, No, ///
														Survey Year FE x Survey FE, No, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, Yes, ///
													    Survey, Gallup) keep(zpwtbar_wgrowth_rate_1) 
